//服务层
app.service('typeService', function($http) {

	//读取列表数据绑定到表单中
	this.findAll = function() {
		return $http.get('../type/findAll.do');
	}
	//分页 
	this.findPage = function(page, rows) {
		return $http.get('../type/findPage.do?page=' + page + '&rows=' + rows);
	}
	//查询实体
	this.findOne = function(id) {
		return $http.get('../type/findOne.do?id=' + id);
	}
	//增加 
	this.add = function(entity) {
		return $http.post('../type/add.do', entity);
	}
	//修改 
	this.update = function(entity) {
		return $http.post('../type/update.do', entity);
	}
	//删除
	this.dele = function(ids) {
		return $http.get('../type/delete.do?ids=' + ids);
	}
	//搜索
	this.search = function(page, rows, searchEntity) {
		return $http.post('../type/search.do?page=' + page + "&rows=" + rows, searchEntity);
	}

	//上传图片
	this.upload = function() {
		//创建表单对象
		var formData = new FormData();
		/*var file = document.querySelector('input[type=file]').files[0];*/
		var file = document.querySelector('input[id=imageShow]').files[0];
		//设置表单
		formData.append('file', file);
		return $http({
			method: "post",
			url: "/file/upload.do",
			data: formData,
			headers: {
				'Content-Type': undefined
			},
			transformRequest: angular.identity
		});
	}
});